package Object;

import java.util.Arrays;
import java.util.StringJoiner;
//Cloneable:标记性接口，无抽象方法
//表示一旦实现，当前类的对象可被克隆，否则不能被克隆
public class user implements Cloneable{
    private int id;
    private  String username;
    private String password;
    private String path;
    private int[] data;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int[] getData() {
        return data;
    }

    public void setData(int[] data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "角色编号为："+id+","+"用户名为："+username+","+"密码为："+password+","+"游戏图片为："+path+","+"游戏进度为："+arrString();
    }

    public user() {
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();//对用父类的方法
        int[] data=this.data;
        int[] newData=new int[data.length];
        for (int i = 0; i < newData.length; i++) {
            newData[i]=data[i];
        }
        user u=(user)super.clone();
        u.data=newData;
        return u;
    }

    public String arrString(){
        StringJoiner stringJoiner=new StringJoiner(",","[","]");
        for (int i = 0; i < data.length; i++) {
            stringJoiner.add(data[i]+"");
        }
        return stringJoiner.toString();
    }

    public user(int id, String username, String password, String path, int[] data) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.path = path;
        this.data = data;
    }
}
